from PolymorphismTables import PolymorphismTables
import numpy.matlib as np
import SiteFrequencySpectrum as sfs

class PowerPoint:
	
	myPolyspect = None
	numPowerSimulations = 0
	myPower = 0.0
	myBeta = 1.0
	myAlpha = 0.05
	myRejected = 0

	myAltSFSs = []
	myAltSummaryStats = []
	
	def __init__(self, inPolyspect, iAltSFS):
		self.myPolyspect = inPolyspect
		self.myAltSFSs = iAltSFS
		self.numPowerSimulations = len(iAltSFS)
		
		self.__operationOnAllSFSs()
		
		self.myRejected = self.myPolyspect.testAltHypotheses( self.myAltSummaryStats )
		
		numRejected = 1.0 * np.sum( self.myRejected )
		self.myPower = 1.0 * numRejected / self.numPowerSimulations
		self.myBeta = 1.0 - self.myPower
			
	def __operationOnAllSFSs(self):
		self.myAltSummaryStats = []
		
		self.myAltSummaryStats = self.myPolyspect.operateOnAll( self.myAltSFSs )
		return self.myAltSummaryStats
	
	def __str__(self):
		s = "Power\t" + str(self.myPower) + "\t" + str(self.myPolyspect)
		return s
	
	def getPower(self):
		return self.myPower
	
	def getOperator(self):
		return self.myPolyspect.myOperator

#	def __generateAltSimulations(self, altDemography):
#		pt = PolymorphismTables()
#		msCommand = self.myPolyspect.myParameters.getAlternativeMSString( self.numPowerSimulations, altDemography )
#		
#		msOut = pt.runMS(msCommand)
#		pt.readMS(None, msOut)
#		self.myAltSFSs = sfs.SiteFrequencySpectrum(pt)
#		
#		return self.myAltSFSs

